//
//  StrateView.m
//  ErWa
//
//  Created by 王阳阳 on 16/3/16.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "StrateView.h"
#import "UserCell.h"
#import "FreeViewController.h"
#import "AppDelegate.h"
#import "StrategyVC.h"
#import "StrategyOtherViewController.h"
#import "BaseTabBarViewController.h"
#import "UIColor+UIColor.h"
@interface StrateView ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UserCell *bigcell;//大的CollecTionView的cell
@property (nonatomic, strong) UICollectionView *bigcollectionView;//collectionView
@property (nonatomic, strong) NSMutableArray *picArr;//图片数组
@property (nonatomic, strong) NSMutableArray *titleArr;//名字数组
@property (nonatomic, strong) NSMutableArray *colUrlArr;//collectionView网址的数组

@end

@implementation StrateView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creat];
    }
    return self;
}
- (void)creat{
    
    NSArray *nameArr =@[@"免费设计",@"装修日记",@"旧房装修",@"省钱秘笈",@"装修搭配", @"买买买"];
    self.titleArr = [nameArr mutableCopy];//label数组
    NSArray *pic = @[@"C13",@"C14",@"C15",@"C16",@"C17",@"C18"];
    self.picArr = [pic mutableCopy];//图片数组
    
    
    //Layout布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((self.frame.size.width - 25) / 4, (self.frame.size.width - 25) / 3.5);
    layout.sectionInset = UIEdgeInsetsMake(5, 10, 5, 10);//边距
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;//横向滑动
    //创建CollectionView
    self.bigcollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 100) collectionViewLayout:layout];
    [self addSubview:_bigcollectionView];
    self.bigcollectionView.backgroundColor = [UIColor clearColor];
    _bigcollectionView.dataSource = self;//代理
    _bigcollectionView.delegate = self;
    _bigcollectionView.showsHorizontalScrollIndicator = NO;//隐藏CollectionView的线
    [_bigcollectionView registerClass:[UserCell class] forCellWithReuseIdentifier:@"bigcell"];// 注册重用池
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
  
    if (indexPath.item == 0) {//第一个cell进入的页面和奇特cell进入的页面不一样
//        FreeViewController *free = [[FreeViewController alloc]init];
//        free.titlename = _titleArr[indexPath.item];//下一页导航栏title显示的名字
        NSString *name = _titleArr[indexPath.item];
        [self.delegate pushWebAction:name];
    }else{
//        StrategyOtherViewController *other = [[StrategyOtherViewController alloc]init];
//        other.titlename = _titleArr[indexPath.item];//传值到下一页的导航栏名字
        NSArray *arr = @[@"568f4e0c7019c9432c13e3c6",@"568f5134ee78506622fc5849",@"568f51d2ee78506623ef55b9",@"568f4e7b7019c9432b3fc8aa",@"568f4f3e7019c94327b07696"];
        self.colUrlArr = [arr mutableCopy];//传值到网址里的数组
//        other.str =  _colUrlArr[indexPath.item - 1];
        NSString *name = _titleArr[indexPath.item];
        NSString *str = _colUrlArr[indexPath.item - 1];
        [self.delegate pushAction:str Name:name];
    }

}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.bigcell = [collectionView dequeueReusableCellWithReuseIdentifier:@"bigcell" forIndexPath:indexPath];
    // 判断当前是什么模式
    
    BOOL model = [AccountManager sharedInstance].isNight;
    
    if (model == YES) {
        _bigcell.backgroundColor = [UIColor changeColorWithString:@"#a1a3a6"];
        
        _bigcollectionView.backgroundColor =  [UIColor changeColorWithString:@"#a1a3a6"];
        
    } else {
        _bigcell.backgroundColor = [UIColor clearColor];
        _bigcollectionView.backgroundColor = [UIColor clearColor];
    }

    _bigcell.nameLabel.text = _titleArr[indexPath.item];
    _bigcell.imageview.image = [UIImage imageNamed:_picArr[indexPath.item]];
    return _bigcell;

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
